package com.yzy.fly.mapper;

import com.yzy.fly.entity.core.FlyFieldCascade;
import com.yzy.fly.kernel.mapper.FlyBasicMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;


@Mapper
public interface FlyFieldCascadeMapper extends FlyBasicMapper<FlyFieldCascade> {

    @Select("select * from fly_field_cascade a where 1=1")
    List<FlyFieldCascade> selectAll();

    @Select("select * from fly_field_cascade a where 1=1 and a.classId = #{classId} order by a.seq asc")
    List<FlyFieldCascade> selectAllByClassId(@Param("classId") int classId);

    @Select("select * from fly_field_cascade a where 1=1 and a.id = (select b.fieldId from fly_field_annotation b where b.id = #{annotationId})")
    FlyFieldCascade selectOneByAnnotationId(@Param("annotationId") int annotationId);

    @Select("select * from fly_field_cascade a where 1=1 and a.name = #{name}")
    FlyFieldCascade selectOneByName(@Param("name") String name);

    /**
     * 批量插入（mysql）
     * @param entityList
     * @return
     */
    Integer insertBatchSomeColumn(Collection<FlyFieldCascade> entityList);


    @Delete({"delete a from fly_field_cascade a where 1=1 ",
            "and a.attrId = #{attrId}"
    })
    int deleteByAttrId(@Param("attrId")int attrId);
    @Delete({"<script>"+
            "delete a from fly_field_cascade a where 1=1 " +
            "and a.attrIds in "+
            "<foreach item='attrId' index='index' collection='attrIds' open='(' separator=',' close=')'>"+
            "#{attrId}"+
            "</foreach>"+
            "</script>"
    })
    int deleteByAttrIds(@Param("attrIds")int[] attrIds);

    @Select("select * from fly_field_cascade a where 1=1 and a.modelId = #{modelId}")
    int deleteByModelId(@Param("modelId") Integer modelId);

    @Select("select * from fly_field_cascade a where 1=1 and a.classId = #{classId}")
    int deleteByClassId(@Param("classId") Integer classId);
}